package ua.kpi_java_training.nikishov.module1;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * Test for Palindrome class.
 *
 * @author Alexey Nikishov.
 */
public class PalindromeTest {

    @After
    public void tearDown() {
        Palindrome.palindromes.clear();
    }

    /**
     * Test of a method that finds all palindromes
     * in entered line that contains palindromes.
     */
    @Test
    public void testFindPalindromes() {
        String inputLine = "minimdad";
        ArrayList<String> expectedPalindromes = new ArrayList<String>(
                Arrays.asList("ini", "dad", "minim")
        );
        Palindrome.findPalindromes(inputLine);
        assertEquals(Palindrome.palindromes, expectedPalindromes);
    }

    /**
     * Test of a method that finds all palindromes
     * in entered line that doesn't contain palindromes.
     */
    @Test
    public void testFindPalindromesFalse() {
        String inputLine = "hello world";
        ArrayList<String> expectedPalindromes = new ArrayList<String>();
        Palindrome.findPalindromes(inputLine);
        assertEquals(Palindrome.palindromes, expectedPalindromes);
    }


    /**
     * The test of a method that finds all palindromes specified length
     * in line that contains palindromes.
     */
    @Test
    public void testFindPalindromesSpecialLength() {
        String inputLine = "minimdad";
        int palindromeLength = 5;
        ArrayList<String> expectedPalindromes = new ArrayList<String>(
                Arrays.asList("minim")
        );
        Palindrome.findPalindromesSpecialLength(palindromeLength, inputLine);
        assertEquals(Palindrome.palindromes, expectedPalindromes);
    }

    /**
     * The test of a method that finds all palindromes specified length
     * in line that doesn't contain palindromes specified length.
     */
    @Test
    public void testFindPalindromesSpecialLengthFalse() {
        String inputLine = "minimdad";
        int palindromeLength = 6;
        ArrayList<String> expectedPalindromes = new ArrayList<String>();
        Palindrome.findPalindromesSpecialLength(palindromeLength, inputLine);
        assertEquals(Palindrome.palindromes, expectedPalindromes);
    }

    /**
     * The test of method which checks whether a given word is a palindrome.
     */
    @Test
    public void testIsPalindrome() {
        String word = "reviver";
        assertTrue(Palindrome.isPalindrome(word));
    }

    /**
     * The test of method which checks whether a given word is a palindrome.
     */
    @Test
    public void testIsPalindromeFalse() {
        String word = "hello";
        assertFalse(Palindrome.isPalindrome(word));
    }

}
